package stuMaiFrame;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.rORM.core.Query;
import com.rORM.core.QueryFactory;

import database.LessonTable;
import database.Score;
import database.Student;
import util.GetStuInfo;
import util.SelectTableModel;

import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JTable;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SelectGrades extends JFrame {
	private Student stu;
	private int cn;
	private JPanel contentPane;
	private JTable table;
	private SelectTableModel model = new SelectTableModel();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		Query q = QueryFactory.createQuery();
		Student s = (Student)q.queryUniqueRow("select * from student where id = ?", Student.class, new Object[]{16402});
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SelectGrades frame = new SelectGrades(s);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SelectGrades(Student stu) {
		setVisible(true);
		this.stu = stu;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 826, 302);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(6, 147, 814, 95);
		contentPane.add(scrollPane);
		
		table = new JTable(model);
		GetStuInfo stuInfo = new GetStuInfo();
		model.addRow(stuInfo.getUniqueRowStuInfo(stu));
		cn = stuInfo.getCn();
	
		if (cn == 0){
			JOptionPane.showMessageDialog(null,"未查到该同学信息！","信息提示框",JOptionPane.INFORMATION_MESSAGE);
			setVisible(false);
		}
		
	
		scrollPane.setViewportView(table);
		
		JLabel lblNewLabel = new JLabel("你的成绩为");
		lblNewLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
		lblNewLabel.setBounds(165, 68, 113, 37);
		contentPane.add(lblNewLabel);
		
		JLabel label = new JLabel(stu.getName());
		label.setForeground(Color.RED);
		label.setFont(new Font("Lucida Grande", Font.PLAIN, 20));
		label.setBounds(40, 58, 113, 60);
		contentPane.add(label);
		
		JButton button = new JButton("返回");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		button.setBounds(703, 245, 117, 29);
		contentPane.add(button);
	}
}
